﻿using GameEditor;
using GameEditor.View.Components;
using GameEngine.Model;
using GameEngine.Model.Data;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using System;
using GameEngine;
using GameEditor.View;

namespace GameEditor.Commands
{
    public class Page_LevelEditorMenu_Action_Command<MyIdType> : SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            //bool exit = false;
            var mediator = Facade.RetrieveMediator(GameEditorFacade.LevelEditorMediatorName) as LevelPropertiesEditor_MenuMediator<MyIdType>;            
            switch ((ILevelEditorMenuViewConstants.ButtonTags)notification.Body)
            {
                case ILevelEditorMenuViewConstants.ButtonTags.CANCEL:
                    //SendNotification(MyFacade.MY_PAGE_GAMESEDITOR_IN_COMMAND);
                    break;
                case ILevelEditorMenuViewConstants.ButtonTags.OK:
                    //mediator to proxy, to file
                    break;
                case ILevelEditorMenuViewConstants.ButtonTags.NEWWORLD:
                    /*{
                        var vo = SilverlightModelFacade.Instance.CreateLevelVO(new LevelVOId<int>(SilverlightModelFacade.Instance.CreateNewId(), "level"));
                        var dataProxy = SilverlightModelFacade.Instance.CreateLevelDataProxy(vo);
                        var med = SilverlightEditorViewFacade.Helper.CreateLevelPropertiesEditor(dataProxy);
                        med.ViewComponent.OnExternalActionButtonClick += new OnButtonClickHandler<ILevelEditorMenuViewConstants.ButtonTags>(delegate(ILevelEditorMenuViewConstants.ButtonTags tag)
                        {
                            switch ((ILevelEditorMenuViewConstants.ButtonTags)notification.Body)
                            {
                                case ILevelEditorMenuViewConstants.ButtonTags.OK:
                                case ILevelEditorMenuViewConstants.ButtonTags.CANCEL:
                                    ApplicationFacade.Instance.RemoveMediator(med.MediatorName);
                                    break;
                            }
                        });
                        gameDataProxy.AddLevel(dataProxy);
                    }*/
                    {
                        var vo = new WorldVO<MyIdType>(new WorldVOId("New World" + ModelFacade<MyIdType>.Instance.CreateNewId()));
                        ApplicationFacadeHelper<MyIdType>.CreateWorld(vo);
                        var dataProxy = ModelFacade<MyIdType>.Helper.GetWorldDataProxy(vo);
                        //SendNotification(SilverlightEditorFacade<GameUC, LevelUC>.MY_PAGE_WORLDEDITOR_IN_COMMAND, dataProxy);
                    }
                    break;
                case ILevelEditorMenuViewConstants.ButtonTags.EDITWORLD:
                    //{
                        //var dataProxy = MyModelFacade.Helper.GetLevelDataProxy(mediator.SelectedWorld);
                        //SendNotification(MyFacade.MY_PAGE_LEVELEDITOR_IN_COMMAND, dataProxy);
                    //}
                    break;
            }
        }
    }
}
